class People {
  public name!: string;
}

class ChinesePeople extends People {
  public age!: number;
}

// Extract 是ts提供的一个ts高级type类型[简称TS高级类型]

// type Extract<T, U> = T extends U ? T : never;

// ! (1)子类 extends 父类 返回true=>返回T类型
type extractType = Extract<ChinesePeople, People>; // ChinesePeople

// ! (2) 父类 extends 子类 返回false=>返回never类型
type extractType2 = Extract<People, ChinesePeople>; // never

// ? 如果people类里面没有新添加的属性,也就是相等了
// type extractType2 = Extract<People,ChinesePeople>// People

// !(3) 联合类型

type unionExtractType = Extract<string, string | number>; // string

type extractUnionType2 = Extract<string | number, string | number>; // string | number

type extractUnionType3 = Extract<string | number, string | number | symbol>; // string | number

// 分解判断
/**
 * 1. string extends string ? T : never // =>string
 * 2. number extends string ? T : never // =>never
 * 合起来结果 string | boolean
 */
type extractUnionType4 = Extract<string | number, string>; //string

type extractUnionType5 = Extract<string | number | symbol, string | number>; // string | number

// !跟类型断言的对比

function test(one: string | number, two: string) {
  // all right
  one as number;
  one as string;
  one as any;

  two as string | number;// 可以少变成联合类型

  console.log("typeof one", typeof one);
  console.log("typeof two", typeof two);
}

test("111", "222");


// !(4) 函数的泛型约束

type func1 = (one: number, two: string) => string
type func2 = (one: number) => string

//? 函数类型上的泛型约束 [参数类型和返回值完全相同]的情况下，
//  参数少的函数类型 extends 参数多的函数类型 返回true
//  参数多的函数类型 extends 参数少的函数类型 返回false
type beginType1 = func1 extends func2 ? func1 : never// never
type beginType2 = func2 extends func1 ? func2 : never// never

type extractFunType1 = Extract<func1, func2>//never func1参数多 不匹配所以是nerver
type extractFunType2 = Extract<func2, func1>//= (one: number) => string 返回参数少的


export { }


export {};
